package com.heima.tlias.dao;

import com.github.pagehelper.Page;
import com.heima.tlias.controller.request.StudentQueryRequest;
import com.heima.tlias.pojo.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    /**
     * 根据班级id查询学生
     *
     * @param clazzId
     * @return
     */
    @Select("select count(*) from student where clazz_id = #{clazzId}")
    Long queryByClazzId(Integer clazzId);

    /**
     * 根据条件查询学生列表
     *
     * @param request
     * @return
     */
    Page<Student> queryList(StudentQueryRequest request);

    /**
     * 新增学生
     *
     * @param student
     */
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @Insert("insert into student values (null,#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{violationCount},#{violationScore},#{createTime},#{updateTime})")
    void insert(Student student);

    /**
     * 根据id查询班级详情
     *
     * @param id
     * @return
     */
    @Select("select * from student where id = #{id}")
    Student queryById(Integer id);

    /**
     * 根据id修改学生信息
     *
     * @param student
     */
    void updateById(Student student);

    /**
     * 批量删除学生信息
     *
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 学员学历统计
     * @return
     */
    List<Map<String, Object>> studentDegreeCount();
}
